using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Domain.Entities;
using Domain.Services;

namespace UserInterface.Admin
{
    public partial class EditCategory : System.Web.UI.Page
    {
        protected Category category;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            byte categoryId = byte.Parse(Request.QueryString["categoryId"]);
            category = CategoryService.GetById(categoryId);
            if (category == null)
            {
                Response.Redirect("ManageForums.aspx");
            }
            if (!IsPostBack)
            {
                NameTextBox.Text = category.Name;
                Title = (string)GetLocalResourceObject("Title");
            }
        }

        protected void OkButton_OnClick(object sender, EventArgs e)
        {
            string name = NameTextBox.Text;
            CategoryService.UpdateCategory(category, name);
            Response.Redirect("ManageForums.aspx");
        }

        protected void CancelButton_OnClick(object sender, EventArgs e)
        {
            Response.Redirect("ManageForums.aspx");
        }
    }
}
